import pymysql
import pandas as pd


class HouseData(object):
    def __init__(self):
        Host = '127.0.0.1'
        User = 'root'
        Password = ''
        dbname='szhouse'

        db = pymysql.connect(Host,User,Password,dbname,charset="utf8")
        sql = 'select * from lianjiav4'
        data = pd.read_sql(sql,db,index_col='id')
        self.data=data
        # print(data)

    def xqmc(self):
        title = '深圳小区挂牌数量排名-TOP20'
        data = self.data['xqmc'].value_counts()
        xqmc = data[:20]
        # print(xqmc)
        return xqmc,title

    def szqy(self):
        title = '深圳各大区域销售中二手房占比'
        data = self.data['szqy'].value_counts()
        szqy = data
        # print(szqy)
        return szqy,title
    def jd(self):
        title = '深圳地区/街道排名'
        data = self.data['jd'].value_counts()
        jd = data
        return jd,title
    def gpsj(self):
        title = '深圳每日挂牌数量'
        data = self.data['gpsj'].value_counts()
        gpsj = data.sort_index(ascending=False)[:200]
        print(gpsj)
        return gpsj,title